package study.dq.date;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 当前时间加上或者减去几天时间
 *
 * @author dongqun
 * @version 1.0.0
 * @ClassName Test.java
 * @createTime 2020年11月17日 15:08:00
 */
public class DateCalculate {

    public static int hours;

    public static Date getAimDate(){
        Calendar calendar = Calendar.getInstance();
        if (DateCalculate.hours()==1){
            calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY)-1);
        }else if (DateCalculate.hours()==24){
            calendar.set(Calendar.DAY_OF_YEAR,calendar.get(Calendar.DAY_OF_YEAR) - 1);
        }else {
            calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - 7);
        }
        return calendar.getTime();
    }

    private static int hours() {
        return hours;
    }


    public static void main(String[] args) {
        hours=24;
        Date date = getAimDate();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(format.format(date));
    }


}
